<script>
$(document).ready(function(){	
	
	jQuery.extend(jQuery.validator.messages, {
	  required: '*',
	  remote: '*'
	});
	
	$("#companyinformationform").validate({
		errorClass: "my-error-class",
		validClass: "my-valid-class",
		debug: false,
		rules: {
			companyname: "required"
			/*companyaddress : "required",
			companyemail: {
					required: true,
					email: true
				},
			zipcode : "required",
			landline : "required",
			faxno : "required",
			mobileno1 : "required",
			mobileno2 : "required",
			cityname : "required",
			country : "required",
			countrycode : "required",
			websiteurl : "required",
			firstname : "required",
			lastname : "required",
			middlename : "required",
			personemail : "required"*/
		},
		submitHandler: function(form){
			$.post("scripts/addcompanyinformation.php", $("#companyinformationform").serialize(), function(data){
				//alert(data);
				//location.reload();
				cleanDiv();
			});
		}
	});
	
	
	$("#companynamelimo").autocomplete({
		source: "scripts/getcity.php",
		minLength: 2,
		change: function(event,ui){
			$("input#country").val(ui.item.country);
			$("input#countrycode").val(ui.item.countrycode);
			$("input#websiteurl").focus();
		},
		open: function() {
			$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
		},
		close: function() {
			$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
		}
	});	

function cleanDiv(){
	var frm_elements =  companyinformationform.elements;
		for (i = 0; i < frm_elements.length; i++)
		{
			field_type = frm_elements[i].type.toLowerCase();
			switch (field_type)
			{
			case "text":
			case "password":
			case "textarea":
			case "hidden":
				frm_elements[i].value = "";
				break;
			case "radio":
			case "checkbox":
				if (frm_elements[i].checked)
				{
					frm_elements[i].checked = false;
				}
				break;
			case "select-one":
			case "select-multi":
				frm_elements[i].selectedIndex = -1;
				break;
			default:
				break;
			}
		}
		
		alert("Saved!");
	}
});
</script>

<div id="addlimoinformation">
	<label> <font color="red">*</font> required field/s </label>
 	<fieldset> 
	<form id="limoinformationform" method="post" action="">
	<legend> <h3> Company </h3> </legend>
	<p>
		<input type="text" id="companynamelimo" name="companynamelimo" autocomplete="off" placeholder="Company Name"/>
	</p>
	
	<p> <hr class="hr1">  </p>
	
	<p> <hr class="hr1">  </p>
	<h3> Rates </h3>
		<table id="table_id" border="1" width="100%"  bordercolor="#dedede">
		<tr>
			<td style="vertical-align: top" >
			One Way/Airport Vehicle </br>
			<label for="vehicletype" style="position: relative; top: 15px; left: 75px"> Vehicle Type </label><br> <label for="Capacity" style="position: relative; left: 280px"> Destination (From-To)</label> <label for="vehiclemodel" style="position: relative; left: 380px">Rate</label></br>
				<input type="text" name="vehicletypeone[]" id="vehicletypeone" class="searchinput" placeholder="Vehicle Type" style="width: 200px;"/> 
				<input type="text" name="distanceone[]" id="distanceone"  placeholder="Distance (From-To)" style="position: relative; left: -5px; width: 200px;"/>
				<input type="text" name="rateone[]" id="rateone"  placeholder="Rate" style="position: relative; left: -8px; width: 100px;"/>
				<span id="mySpanvehicle"><br></span><br>
				<input name="btnButton" type="button" value="+ Add More" onClick="JavaScript:fncCreateElement();"> <br>
				<!-- <a href=javascript:void(0);  onclick="addRow();">Add More</a>	-->			
			</td>
			<td style="vertical-align: top">
			Hourly Vehicle </br>
			<label for="vehicletype" style="position: relative; top: 15px; left: 75px"> Vehicle Type </label><br> <label for="Capacity" style="position: relative; left: 280px"> Destination (From-To)</label> <label for="vehiclemodel" style="position: relative; left: 380px">Rate</label></br>
				<input type="text" name="vehicletypehourly[]" id="vehicletypehourly"  placeholder="Vehicle Type" style="width: 200px;"/> 
				<input type="text" name="minimumhourly[]" id="minimumhourly"  placeholder="Number of hours" style="position: relative; left: -5px; width: 200px;"/>
				<input type="text" name="ratehourly[]" id="ratehourly"  placeholder="Rate" style="position: relative; left: -5px; width: 100px;"/>
				<span id="mySpanvehiclehourly"><br></span><br>
				<input name="btnButton" type="button" value="+ Add More" onClick="JavaScript:fncCreateElementhourly();"> <br>
			</td>
		</tr>
		</table>
		<br />
		
	<p> <hr class="hr1">  </p>
		<input type="submit" value="Submit"> <input type="reset" value="Clear">
		
	</form>	
	</fieldset>
</div>
